<?php
namespace app\farm\controller;
use app\ApiRest;

use app\farm\model\Config;
use app\farm\model\FinanceWater;
use app\farm\model\InfoRecord;
use app\farm\model\SystemInfo;
use app\farm\model\User;

use app\farm\model\Wallet;
use app\farm\model\WelfareColumn;
use app\shop\model\DistributionCash;
use app\shop\model\DistributionList;

use think\App;
use think\facade\Db;
use think\Request;


class IndexInfo extends ApiRest
{

    protected $model;

    protected $user_model;

    protected $cash_model;

    public function __construct(App $app) {

        parent::__construct($app);

        $this->model = new SystemInfo();

        $this->info_model  = new WelfareColumn();

        $this->record_model  = new InfoRecord();



    }


    /**
     * @author chenniang
     * @DataTime: 2022-08-22 15:13
     * @功能说明:查看自己的系统公告
     */
    public function systemInfoList(){

        $dis[] = ['uniacid','=',$this->_uniacid];

        $dis[] = ['user_id','=',$this->getUserId()];

        $count = $this->model->where($dis)->where(['status'=>0])->count();

        $this->model->where($dis)->where(['status'=>0])->update(['status'=>1]);

        $dis[] = ['status','>',-1];

        $data = $this->model->dataList($dis);

        $data['no_read_count'] = $count;

        $data['operate_no_read_count'] = $this->record_model->noReadCount($this->getUserId(),$this->_uniacid);

        return $this->success($data);

    }


    /**
     * @author chenniang
     * @DataTime: 2022-08-22 15:54
     * @功能说明:运营公告
     */
    public function operateInfoList(){

        $dis[] = ['uniacid','=',$this->_uniacid];

        $dis[] = ['type','=',3];

        $dis[] = ['status','=',1];

        $data = $this->info_model->dataList($dis);
        //未读消息数量
        $data['operate_no_read_count'] = $this->record_model->noReadCount($this->getUserId(),$this->_uniacid);

        $where[] = ['uniacid','=',$this->_uniacid];

        $where[] = ['user_id','=',$this->getUserId()];

        $data['no_read_count'] = $this->model->where($where)->where(['status'=>0])->count();

        return $this->success($data);
    }


    /**
     * @author chenniang
     * @DataTime: 2022-08-22 16:16
     * @功能说明:运营公告详情
     */
    public function operateInfoInfo(){

        $input = $this->_param;

        $data = $this->info_model->dataInfo(['id'=>$input['id']]);

        $insert = [

            'user_id' => $this->getUserId(),

            'uniacid' => $this->_uniacid,

            'info_id' => $input['id']
        ];

        $find = $this->record_model->dataInfo($insert);

        if(empty($find)){

            $this->record_model->dataAdd($insert);
        }

        return $this->success($data);
    }



















}
